package org.chatty;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;

public class Saver {

	private AudioFormat audioFormat_;
	private AudioFileFormat.Type fileType_;
	private OutputStream outputStream_;

	private String filename_;

	public Saver() {
	}

	public Saver( AudioFormat audioFormat, AudioFileFormat.Type fileType, OutputStream outputStream ) {
		this.setAudioFormat( audioFormat );
		this.setFileType( fileType );
		this.setOutputStream( outputStream );
	}

	//// methods to implement the Recorder.CallBack interface

	// TODO: put this in a separate thread...
	public void recorderCallBack( byte audioData[] ) {
		try {
			Util.write(
				audioData
				, this.getAudioFormat()
				, this.getFileType()
				, this.getOutputStream()
			);

		} catch( Exception e ) {
			// FIXME: don't do this sort of silly thing
			e.printStackTrace();
		}
	}   

	public void recorderError( Exception exception ) {
		System.out.println( "ouch " + exception );
	}   

	////

	public AudioFormat getAudioFormat() {
		return this.audioFormat_;
	}

	public void setAudioFormat( AudioFormat audioFormat ) {
		this.audioFormat_ = audioFormat;
	}

	public AudioFileFormat.Type getFileType() {
		return this.fileType_;
	}

	public void setFileType( AudioFileFormat.Type fileType ) {
		this.fileType_ = fileType;
	}

	public OutputStream getOutputStream() {
		return this.outputStream_;
	}

	public void setOutputStream( OutputStream outputStream ) {
		this.outputStream_ = outputStream;
	}


};
